<?php


namespace app\api\controller;

use app\common\controller\ApiController;
use Swoole\Server\Task;
use think\App;

use app\common\model\DimCategory;
use think\console\command\make\Model;
use think\Exception;
use think\exception\HttpResponseException;
use \app\common\model\TaskRelease as TaskReleaseModel;

class taskRelease extends ApiController
{

    public function __construct()
    {
        parent::__construct();
        $this->model = new TaskReleaseModel();
    }

    /**
     * 获取 分类
     *
     */
    public function categoryList()
    {

        $dim_category_model = new DimCategory();
        $result = $conditions = array();
        $conditions[] = ['type', '=', DimCategory::CATE_TYPE_TASK];
        try{
            $result = $dim_category_model->getList($conditions);
        }catch (\Exception $e){
            self::_result([], -1, $e->getMessage());
        }
        self::_result($result);
    }

    /**
     * 获取 发布列表
     *
     */
    public function list()
    {

        $page = input('page', '1');
        $page_size = input('page_size', '10');
        $category_id = input('category_id', '');

        $result = $conditions = array();
        $conditions[] = array('a.status', '=', TaskReleaseModel::STATUS_PUBLISH_YES);
        empty($category_id) ?: $conditions[] = array('a.cate_id', '=', $category_id);
        try{
            $result = $this->model->getListInfo($conditions, $page, $page_size);
        }catch (Exception $e){
            self::_result([], -1, $e->getMessage());
        }
        self::_result($result);
    }

    /**
     * 发布详情
     *
     */
    public function detail()
    {

        $task_id = input('task_id', '');
        if(empty($task_id)){ self::_result([], -1, '发布任务id不能为空'); }

        $result = $conditions = array();
        $conditions[] = array('a.id', '=', $task_id);
        try{
            $result = $this->model->getDetail($conditions);
        }catch (\Exception $e){
            self::_result([], -1, $e->getMessage());
        }
        self::_result($result);
    }
}